package com.jozen.smart_toilet_system.ui;

import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jozen.modelbase.netwoek.bean.HomeModel;
import com.jozen.smart_toilet_system.R;
import com.ruffian.library.widget.RTextView;

import java.util.List;

public class ManAdapter extends BaseMultiItemQuickAdapter<HomeModel.ListDTO, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ManAdapter(List<HomeModel.ListDTO> data) {
        super(data);
        addItemType(0, R.layout.item_man_list_1);
        addItemType(1, R.layout.item_man_list_2);
        addItemType(2, R.layout.item_man_list_3);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeModel.ListDTO item) {
        try {
            switch (helper.getItemViewType()) {
                case 0:
                case 1:
                    helper.setText(R.id.tv_val, item.getValueStr() + "");
                    helper.setText(R.id.tv_unit, item.getUnit());

                    //告警状态 0正常 大于0告警
                    TextView val = helper.getView(R.id.tv_val);
                    if (item.getState() > 0) {
                        val.setTextColor(ContextCompat.getColor(mContext, R.color.color_E63B3B));
                    } else {
                        val.setTextColor(ContextCompat.getColor(mContext, R.color.black));
                    }
                    break;
                case 2:
                    RTextView tv_unit = helper.getView(R.id.tv_unit_state);
                    helper.setText(R.id.tv_val, item.getValueStr() + "");
                    switch (item.getModelId()) {
                        case 7://PM2.5
                            helper.setText(R.id.tv_unit, "ug/m³");
                            break;
                        case 8://VOC
                            helper.setText(R.id.tv_unit, "mg/m³");
                            break;
                        default://其他拿服务端返回
                            helper.setText(R.id.tv_unit, item.getUnit());
                            break;
                    }
                    TextView view = helper.getView(R.id.tv_val);
                    if (item.getEvnstate() == 0) {
                        view.setTextColor(ContextCompat.getColor(mContext, R.color.color_3EB73E));
                    } else {
                        view.setTextColor(ContextCompat.getColor(mContext, R.color.color_E63B3B));
                    }
                    tv_unit.setVisibility(View.INVISIBLE);

//                    if (item.getEvnstate() == 0) {
//                        tv_unit.setText("优");
//                        tv_unit.getHelper().setBackgroundColorNormal(ContextCompat.getColor(mContext, R.color.color_D4F3D8));
//                        tv_unit.getHelper().setTextColorNormal(ContextCompat.getColor(mContext, R.color.color_3EB73E));
//                    } else {
//                        tv_unit.setText("差");
//                        tv_unit.getHelper().setBackgroundColorNormal(ContextCompat.getColor(mContext, R.color.color_FFDCDC));
//                        tv_unit.getHelper().setTextColorNormal(ContextCompat.getColor(mContext, R.color.color_E63B3B));
//                    }
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
